#include <QtCore>
#include <QFileInfo>
#include "ControlPanel.h"
#include "ui_ControlPanel.h"
#include "ewha.h"
#include <QtDebug>

ControlPanel::ControlPanel(QWidget *parent) :
	QWidget(parent),
	ui(new Ui::ControlPanel)
{
	ui->setupUi(this);

	m_lamp[0] = ui->lampStandby;
	m_lamp[1] = ui->lampReady;
	m_lamp[2] = ui->lampCapture;
	m_lamp[3] = ui->lampCaptureEnd;

	qDebug() << "align" << ui->verticalLayout_4->setAlignment(ui->btnReset, Qt::AlignRight);
	qDebug() << "align" << ui->verticalLayout_4->setAlignment(ui->btnExit, Qt::AlignRight);
	qDebug() << "align" << ui->gridLayout->setAlignment(ui->btnStandby, Qt::AlignCenter);
	qDebug() << "align" << ui->gridLayout->setAlignment(ui->btnReady, Qt::AlignCenter);
	qDebug() << "align" << ui->gridLayout->setAlignment(ui->btnCapture, Qt::AlignCenter);
	qDebug() << "align" << ui->gridLayout->setAlignment(ui->btnCaptureEnd, Qt::AlignCenter);
	qDebug() << "align" << ui->gridLayout->setAlignment(ui->lampCapture, Qt::AlignCenter);
	qDebug() << "align" << ui->gridLayout->setAlignment(ui->lampCaptureEnd, Qt::AlignCenter);
	qDebug() << "align" << ui->gridLayout->setAlignment(ui->lampReady, Qt::AlignCenter);
	qDebug() << "align" << ui->gridLayout->setAlignment(ui->lampStandby, Qt::AlignCenter);
	qDebug() << "align" << ui->verticalLayout_2->setAlignment(ui->spbCurrent, Qt::AlignCenter);
	qDebug() << "align" << ui->verticalLayout_3->setAlignment(ui->spbTime, Qt::AlignCenter);
	qDebug() << "align" << ui->verticalLayout->setAlignment(ui->spbVoltage, Qt::AlignCenter);

	connect(ui->btnExit, SIGNAL(clicked()), SIGNAL(SignalExitCapture()));
	connect(ui->btnReady, SIGNAL(clicked()), SIGNAL(SignalReady()));
}

ControlPanel::~ControlPanel()
{
	delete ui;
}

void ControlPanel::setLamp(int pos, EColor color)
{
	m_lamp[pos]->changeState(color);
}

void ControlPanel::reset()
{
	this->setLamp(0, eStGray);
	this->setLamp(1, eStGray);
	this->setLamp(2, eStGray);
	this->setLamp(3, eStGray);
}

void ControlPanel::SlotStandby()
{
	this->reset();
	//전압, 전류 * 100, 시간 * 10
	emit SignalStandby(qRound(ui->spbVoltage->value()), qRound(ui->spbCurrent->value() * 100), qRound(ui->spbTime->value() * 10));
}
